package com.hust.edu.cn.service.impl;

import com.hust.edu.cn.entity.Type;
import com.hust.edu.cn.mapper.TypeMapper;
import com.hust.edu.cn.service.TypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类：实现分类业务层接口
 * </p>
 *
 * @author Yu Jian
 * @since 2021-07-06
 */
@Service
public class TypeServiceImpl extends ServiceImpl<TypeMapper, Type> implements TypeService {

    @Autowired
    private TypeMapper typeMapper;

    // 新增保存分类
    @Transactional
    @Override
    public int saveType(Type type){
        return  typeMapper.saveType(type);
    }

    // 根据id查询分类
    @Transactional
    @Override
    public Type getType(Long id){
        return typeMapper.getType(id);
    }

    // 查询所有分类
    @Transactional
    @Override
    public List<Type> getAllType(){
        return typeMapper.getAllType();
    }

    @Override
    public List<Type> getAllTypeAndBlog() {
        return typeMapper.getAllTypeAndBlog();
    }

    // 根据分类名称查询分类
    @Override
    public Type getTypeByName(String name){
        return typeMapper.getTypeByName(name);
    }

    // 编辑修改分类
    @Transactional
    @Override
    public int updateType(Type type){
        return typeMapper.updateType(type);
    }

    // 删除分类
    @Transactional
    @Override
    public void deleteType(Long id){
        typeMapper.deleteType(id);
    }
}
